package com.wc.AlgoOJ_train.train1.c5.A404;

import java.util.Scanner;

/**
 * @Author congge
 * @Date 2024/1/8 23:41
 * @description 考新郎
 * http://43.138.190.70:8888/p/A403
 */
public class Main {
    public static void main(String[] args) {
        long[] dp = new long[21];
        long[] div = new long[21];
        dp[1] = 0;
        dp[2] = 1;
        div[0] = 1;
        div[1] = 1;
        div[2] = 2;
        for (int i = 3; i <= 20; i++) {
            dp[i] = (i - 1) * (dp[i - 1] + dp[i - 2]);
            div[i] = div[i - 1] * i;
        }
        Scanner sc = new Scanner(System.in);
        int c = sc.nextInt();
        while (c-- > 0) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            System.out.println(div[n] / div[n - m] / div[m] * dp[m]);
        }
    }
}
